package com.springcloud.demo.service;

import com.springcloud.demo.pojo.Product;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @Author: XiaoJie Wang
 * @Description:
 * @Date: Create in 10:26 2021/7/8
 */
@Slf4j
@Service
public class ProductServiceImpl implements ProductService {
    @Override
    public List<Product> selectProductList() {
        log.info("selectProductList");
        return Arrays.asList(
                new Product(1, "华为手机", 2, 5888D),
                new Product(2, "联想笔记本", 1, 6888D),
                new Product(3, "小米平板", 5, 2666D)
        );
    }

    /**
     * 根据主键查询商品
     *
     * @param id
     * @return
     */
    @Override
    public Product selectProductById(Integer id) {
        System.out.println("selectProductById");
        return new Product(id, "冰箱", 1, 2666D);
    }

    /**
     * 新增商品
     * @param product
     * @return
     */
    @Override
    public Map<String, Object> createProduct(Product product) {
        System.out.println(product);
        return new HashMap<String, Object>() {{
            put("code", 200);
            put("message", "新增成功");
        }};
    }

    /**
     * 接收商品对象参数
     *
     * @param product
     * @return
     */
    @Override
    public Product selectProductByPojo(Product product) {
        System.out.println(product);
        return product;
    }

    /**
     * 根据多个主键查询商品
     *
     * @param ids
     * @return
     */
    @Override
    public List<Product> selectProductListByIds(List<Integer> ids) {
        List<Product> products = new ArrayList<>();
        ids.forEach(id -> products.add(new Product(id, "电视机" + id, 1, 5800D)));
        return products;
    }

}
